﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SphereTranslate : MonoBehaviour
{
    float Speed;
    /*[HideInInspector]
    public float m_vStartPosy;*/
    [HideInInspector]
    public float m_fNowTime;
    [HideInInspector]
    public bool m_b_;
    [HideInInspector]
    public bool m_bFinal;
    [HideInInspector]
    public bool m_bDead;
    [HideInInspector]
    public bool m_bChange=false;
    Vector2 m_vLenght;
    Sprite m_sOrg;
    Sprite m_sNew;
    Image m_image;
    private void Awake()
    {
        Speed = GlobalHelper.MainGame.m_fSphereSpeed / 100;
        m_sOrg= Resources.Load("Image/"+gameObject.name, typeof(Sprite)) as Sprite;
        m_sNew = Resources.Load("Image/" + gameObject.name + gameObject.name, typeof(Sprite)) as Sprite;
        m_vLenght = GetComponent<RectTransform>().sizeDelta;
        m_image = GetComponent<Image>();
    }
    void OnEnable()
    {
        m_bFinal = false;
        m_bChange = false;
        GetComponent<RectTransform>().sizeDelta = m_vLenght;
        m_image.sprite= m_sOrg;
    }
    public void MyUpdate()
    {
        // 4.2小球活性打开向下做运动（position）
        transform.Translate(0, -Speed * Time.deltaTime, 0);
        // 4.3小球的大小逐渐变大（Scale）（Tween Scale Self）
        transform.localScale += new Vector3(0.5f * Time.deltaTime, 0.5f * Time.deltaTime, 0);      
    }
    public void ChangeImage(int time)//换图片
    {        if (m_b_)        {            m_fNowTime--;            if (0 == m_fNowTime)            {                transform.localScale = new Vector3(2f, 2f, 2f);                GetComponent<Image>().sprite = m_sNew;                m_b_ = false;                m_fNowTime = time;            }        }        else        {            m_fNowTime--;            if (0 == m_fNowTime)            {                transform.localScale = new Vector3(1f, 1f, 1f);                GetComponent<Image>().sprite = m_sOrg;                m_b_ = true;                m_fNowTime = time;            }        }    }
}
